﻿using Inovout.Kuajing.Models;
using Inovout.Services;
using System.Linq;

namespace Inovout.Kuajing.Services
{
    public class CommodityService : RepositoryService<Commodity>
    {
        private WangCangStoreService wangCangStoreService;
        public CommodityService()
        {
            wangCangStoreService = new WangCangStoreService();
        }

        public int GetAvailableSaleQuantity(string code)
        {
           
            Commodity commodity = GetByCode(code);
            if (commodity.ExternalShipperId.Equals("310"))
            {
                commodity.Stock = wangCangStoreService.GetCommoditAvailableSaleQuantity(commodity);
                Save(commodity);
            }
            return commodity.Stock;
        }

        public Commodity GetByCode(string code)
        {
            return base.Repository.Query().Single(c => c.Code.Equals(code));
        }
    }
}
